﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel._Admin.SysCodeRuleVms
{
    public partial class SysCodeRuleListVm : BasePagedListVM<SysCodeRuleView, SysCodeRuleSearcher>
    {

        protected override IEnumerable<IGridColumn<SysCodeRuleView>> InitGridHeader()
        {
            return new List<GridColumn<SysCodeRuleView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.CodeType),
                this.MakeGridHeader(x => x.Prefix),
                this.MakeGridHeader(x => x.DateFormat),
                this.MakeGridHeader(x => x.SerialLength),
                this.MakeGridHeader(x => x.Suffix),
                this.MakeGridHeader(x => x.ResetRule),
                this.MakeGridHeader(x => x.CurrentSerial),
                this.MakeGridHeader(x => x.LastGenerateTime),
                this.MakeGridHeader(x => x.LastResetTime),
                this.MakeGridHeader(x => x.IsEnabled),
                this.MakeGridHeader(x => x.Sort),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeader(x => x.TenantCode),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysCodeRuleView> GetSearchQuery()
        {
            var query = DC.Set<SysCodeRule>()
                .CheckContain(Searcher.Name, x=>x.Name)
                .CheckContain(Searcher.CodeType, x=>x.CodeType)
                .CheckEqual(Searcher.IsEnabled, x=>x.IsEnabled)
                .Select(x => new SysCodeRuleView
                {
				    ID = x.ID,
                    Name = x.Name,
                    CodeType = x.CodeType,
                    Prefix = x.Prefix,
                    DateFormat = x.DateFormat,
                    SerialLength = x.SerialLength,
                    Suffix = x.Suffix,
                    ResetRule = x.ResetRule,
                    CurrentSerial = x.CurrentSerial,
                    LastGenerateTime = x.LastGenerateTime,
                    LastResetTime = x.LastResetTime,
                    IsEnabled = x.IsEnabled,
                    Sort = x.Sort,
                    Remark = x.Remark,
                    TenantCode = x.TenantCode,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysCodeRuleView : SysCodeRule{

    }
}
